package com.cq.hd.order.api.vo;

import com.cq.hd.common.enums.biz.SubOrderStateEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

/**
 * @author much
 * @since 2024/11/17 11:17
 */
@Data
public class OrderItemGroupVo {

    @ApiModelProperty(value = "分组编号")
    private Integer itemGroup;

    @ApiModelProperty(value = "报名订单项列表")
    private List<AppOrderItemVo> enrollOrderItems;

    @ApiModelProperty(value = "下单订单项列表(购买订单存在)")
    private List<AppOrderItemVo> appOrderItems;

    @ApiModelProperty(value = "是否已全核销")
    private boolean allVerified;

    public boolean getAllVerified() {
        List<Integer> verifiedStates = Arrays.asList(SubOrderStateEnum.VERIFIED.getValue(), SubOrderStateEnum.SETTLED.getValue());
        enrollOrderItems = Optional.ofNullable(enrollOrderItems).orElse(Collections.emptyList());
        appOrderItems = Optional.ofNullable(appOrderItems).orElse(Collections.emptyList());
        long enrollVerifiedCount = enrollOrderItems.stream()
                .filter(e -> verifiedStates.contains(e.getSubOrderState()))
                .count();
        long goodsVerifiedCount = appOrderItems.stream()
                .filter(e -> verifiedStates.contains(e.getSubOrderState()))
                .count();
        return (enrollVerifiedCount + goodsVerifiedCount) == (enrollOrderItems.size() + appOrderItems.size());
    }

}
